﻿using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DAL
{
	public class MultithreadingDbReader<T> where T : class, new()
	{
		CodeFirstTestMvcDBEntities db = new CodeFirstTestMvcDBEntities();

		public IQueryable<T> LoadPageEntities<s>(int pageIndex, int pageSize, System.Linq.Expressions.Expression<Func<T, bool>> whereLambda, System.Linq.Expressions.Expression<Func<T, s>> orderbyLambda, bool isAsc)
		{
			var temp = db.Set<T>().Where<T>(whereLambda);
			//totalCount = temp.Count();
			if (isAsc)
			{
				temp = temp.OrderBy<T, s>(orderbyLambda).Skip<T>((pageIndex - 1) * pageSize).Take<T>(pageSize);
			}
			else
			{
				temp = temp.OrderByDescending<T, s>(orderbyLambda).Skip<T>((pageIndex - 1) * pageSize).Take<T>(pageSize);
			}
			return temp;
		}


	}
}
